<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Category extends Model
{
    protected $fillable = [
        'title', 'sort', 'extended_data', 'type', 'p_id'
    ];

    protected $casts = [
        'extended_data' => 'array'
    ];

    public function child()
    {
        return $this->hasMany(self::class, 'p_id', 'id');
    }

    public function children()
    {
        return $this->child()->with('children');
    }

    public function childContent()
    {
        return $this->child()->with('content');
    }

    public function content()
    {
        return $this->hasMany(Content::class, 'c_id', 'id');
    }
}
